import { ref, onMounted } from "vue";
import axios from "axios";

export default function useShowDog() {
  //获取一张狗的图片:保存的数据
  const dogUrl = ref("");
  const loading = ref(true);
  //获取一张狗的图片:发送请求
  const getDogUrl = async () => {

    const result = await axios.get("https://dog.ceo/api/breeds/image/random");

    loading.value = false;
    dogUrl.value = result.data.message;
  };

  //获取一张狗的图片:生命周期函数
  onMounted(() => {
    getDogUrl();
  });

  return { dogUrl, loading };
}
